﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;

namespace LdtJudge.DataEngine.Common.StringAssemble
{
    /// <summary>
    /// 字符串处理类
    /// </summary>
    public class LdFormat
    {

        /// <summary>
        /// 对字符串进行格式化
        /// </summary>
        /// <param name="obj">格式化对象</param>
        /// <returns>返回字符串</returns>
        public static string ObjectToString(object obj)
        {
            if (obj == null || obj == DBNull.Value)
            {
                return string.Empty;
            }
            return obj.ToString();
        }

        /// <summary>
        /// 对字符串进行小写格式化
        /// </summary>
        /// <param name="obj">格式化对象</param>
        /// <returns>返回字符串</returns>
        public static string ObjectToLowString(object obj)
        {
            if (obj == null || obj == DBNull.Value)
            {
                return string.Empty;
            }
            return obj.ToString().Trim().ToLower();
        }

        /// <summary>
        /// 把日期值转化为短日期整数；如20070809
        /// </summary>
        /// <param name="oTime">被转换值</param>
        /// <returns>转换后的值</returns>
        public static int DateTimeToShortDateInt(DateTime oTime)
        {
            return Convert.ToInt32(oTime.Year.ToString()
                    + oTime.Month.ToString().PadLeft(2, '0')
                    + oTime.Day.ToString().PadLeft(2, '0'));
        }

        /// <summary>
        /// 对字符串，转换为整形
        /// </summary>
        /// <param name="str">待转换字符串</param>
        /// <returns>转换后的整数值</returns>
        public static int StringToInt(string str)
        {
            int reInt;

            return (int.TryParse(str, out reInt)) ? reInt : 0;
        }

        /// <summary>
        ///  把对象转换为整形
        /// </summary>
        /// <param name="obj">对象</param>
        /// <returns>转换后的整数值</returns>
        public static int ObjectToInt(object obj)
        {
            if (obj == null || obj == DBNull.Value)
            {
                return 0;
            }
            int i;
            int.TryParse(obj.ToString(), out i);
            return i;
        }

        /// <summary>
        /// 将对象转化为DateTime
        /// </summary>
        /// <param name="obj">待格式化对象</param>
        /// <returns>DateTime</returns>
        public static DateTime ObjectToDataTime(object obj)
        {
            if (obj == null || obj == DBNull.Value)
            {
                return DateTime.MinValue;
            }
            try
            {
                return Convert.ToDateTime(obj);
            }
            catch (Exception err)
            {
                return DateTime.MinValue;
            }
        }

        /// <summary>
        /// 日期整数转换为格式化日期字符串
        /// </summary>
        /// <param name="dateInt">六位日期整数,如：20141001</param>
        /// <returns>短日期字符串，如：2014-10-01</returns>
        [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1631:DocumentationMustMeetCharacterPercentage", Justification = "Reviewed.")]
        public static string DateIntToDateString(int dateInt)
        {
            return LdFormat.DateIntToDateString(dateInt.ToString());
        }

        /// <summary>
        /// 日期整数字符串转换为格式化日期字符串
        /// </summary>
        /// <param name="dateIntStr">六位日期字符串,如：20141001</param>
        /// <returns>短日期字符串，如：2014-10-01</returns>
        [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1631:DocumentationMustMeetCharacterPercentage", Justification = "Reviewed.")]
        public static string DateIntToDateString(string dateIntStr)
        {
            if (dateIntStr.Length == 8)
            {
                return dateIntStr.Insert(4, "-").Insert(7, "-");
            }
            else
            {
                return string.Empty;
            }
        }

        #region 内容转全角半角的函数 

        /// <summary>
        /// 转全角的函数(SBC case)
        /// </summary>
        /// <param name="input">任意字符串
        ///     全角空格为12288，半角空格为32
        ///     其他字符半角(33-126)与全角(65281-65374)的对应关系是：均相差65248
        /// </param>
        /// <returns>全角字符串</returns>
        public static String ToSBC(String input)
        {
            // 半角转全角：
            char[] c = input.ToCharArray();
            for (int i = 0; i < c.Length; i++)
            {
                if (c[i] == 32)
                {
                    c[i] = (char)12288;
                    continue;
                }
                if (c[i] < 127)
                    c[i] = (char)(c[i] + 65248);
            }
            return new String(c);
        }


        /// <summary>
        /// 转半角的函数(DBC case)
        /// </summary>
        /// <param name="input">任意字符串
        ///     全角空格为12288，半角空格为32
        ///     其他字符半角(33-126)与全角(65281-65374)的对应关系是：均相差65248
        /// </param>
        /// <returns>半角字符串</returns>
        public static String ToDBC(String input)
        {
            char[] c = input.ToCharArray();
            for (int i = 0; i < c.Length; i++)
            {
                if (c[i] == 12288)
                {
                    c[i] = (char)32;
                    continue;
                }
                if (c[i] > 65280 && c[i] < 65375)
                    c[i] = (char)(c[i] - 65248);
            }
            return new String(c);
        }

        #endregion




        /// <summary>
        /// 去除空格
        /// </summary>
        /// <param name="input">待格式化字符串</param>
        /// <returns>格式化后字符串</returns>
        public static string RemoveSpaceChar(String input)
        {
            return Regex.Replace(input, @"\s*", "");
        }

        /// <summary>
        /// 转化汉语表达的数字为阿拉伯数字
        /// </summary>
        /// <param name="AChineseNumbText">汉语数字</param>
        /// <returns>阿拉伯数字。</returns>
        public static double DecodeNumberCn(string AChineseNumbText)
        {
            try
            {
                double resultValue;
                if (double.TryParse(AChineseNumbText, out resultValue))
                {
                    return resultValue;         //本身就是double，则直接返回
                }

                if (AChineseNumbText == string.Empty)
                    return 0;

                AChineseNumbText = AChineseNumbText.Replace("亿亿", "兆");
                AChineseNumbText = AChineseNumbText.Replace("万万", "亿");
                AChineseNumbText = AChineseNumbText.Replace("点", "元");
                AChineseNumbText = AChineseNumbText.Replace("块", "元");
                AChineseNumbText = AChineseNumbText.Replace("毛", "角");
                AChineseNumbText = AChineseNumbText.Replace("个", "");
                AChineseNumbText = AChineseNumbText.Replace("〇", "零");
                AChineseNumbText = AChineseNumbText.Replace(",", "");           //对格式“1,123,456,789”中的逗号进行替换

                double vResult = 0;
                double vIntegerTemp = 0;              //整数部分缓存值
                double vNumber = 0;
                string tempString = String.Empty;// 当前数字 

                foreach (char vChar in AChineseNumbText)
                {
                    int i = "零一二三四五六七八九".IndexOf(vChar);
                    if (i < 0) i = "洞幺两三四五六拐八勾".IndexOf(vChar);
                    if (i < 0) i = "零壹贰叁肆伍陆柒捌玖".IndexOf(vChar);

                    if (Regex.IsMatch(vChar.ToString(), @"\d"))
                        i = Convert.ToInt32(vChar.ToString());//LdFormat.ObjectToInt(vChar.ToString());

                    if (i == 0)
                    {
                        vIntegerTemp = vIntegerTemp * 10;           //整数位*10;                    
                        continue;
                    }

                    if (i > 0)
                    {
                        if (string.IsNullOrEmpty(tempString))
                        {
                            vNumber = i;

                            vIntegerTemp = vIntegerTemp * 10; //整数位*10;
                            vIntegerTemp += vNumber; //把当前数字追加到当前值序列
                        }
                        else
                        {
                            vIntegerTemp = Convert.ToDouble(tempString + i);
                            tempString += i;
                        }
                    }
                    else
                    {
                        if (vChar.ToString().Equals(".")) //处理小数点
                        {
                            tempString = vIntegerTemp.ToString() + ".";
                        }
                        else
                        {
                            //处理单位
                            i = "元十百千万亿".IndexOf(vChar);
                            if (i < 0) i = "整拾佰仟万亿兆".IndexOf(vChar);
                            if (i == 5) i = 8;
                            if (i == 6) i = 12;
                            if (i > 0)
                            {
                                //当首字符为单位时，默认其数学值为1
                                if (vResult == 0 && vIntegerTemp == 0)
                                    vIntegerTemp = 1;

                                vIntegerTemp = vIntegerTemp * Math.Pow(10, i); ;           //整数位*10;

                                //每处理一个单位，就缓存一次前边的结果值；
                                vResult += vIntegerTemp;
                                vIntegerTemp = 0;
                            }
                            else
                            {
                                i = "元角分".IndexOf(vChar);
                                if (i > 0)
                                {
                                    vIntegerTemp = vIntegerTemp * Math.Pow(10, -i);
                                }
                                //每处理一个单位，就缓存一次前边的结果值；
                                vResult += vIntegerTemp;
                                vIntegerTemp = 0;

                                continue;
                            }
                        }
                    }
                }

                return vResult + vIntegerTemp;
            }
            catch
            {
                return 0.0;
            }
        }

        /// <summary>
        /// 按数据库字段类型，对字段值进行格式化。
        /// </summary>
        /// <param name="fieldType">字段类型</param>
        /// <param name="currFieldValue">字段值</param>
        /// <returns>格式化后的值。</returns>
        public static string FormatDataField(string fieldType, string currFieldValue)
        {
            string convertValue = currFieldValue;
            if (fieldType == "" || fieldType == "varchar" || fieldType == "nvarchar" || fieldType == "ntext")
            {
                fieldType = "string";
            }
            if ((fieldType == "int" || fieldType == "money") && !Regex.IsMatch(convertValue, @"^\d*$"))
            {
                //支持对不规范的日期区间，转化为天数！
                if (Regex.IsMatch(currFieldValue, "年|月"))
                {
                    double nYear = LdFormat.DecodeNumberCn(Regex.Match(currFieldValue, @"[零一二三四五六七八九十\d]*(?=年)").Value);
                    double nMonth = LdFormat.DecodeNumberCn(Regex.Match(currFieldValue, @"[零一二三四五六七八九十\d]*(?=个?月)").Value);
                    double nDay = LdFormat.DecodeNumberCn(Regex.Match(currFieldValue, @"[零一二三四五六七八九十\d]*(?=日|天)").Value);

                    convertValue = (nYear * 360 + nMonth * 30 + nDay).ToString();
                }
                else
                    convertValue = LdFormat.DecodeNumberCn(convertValue).ToString();
            }

            if (fieldType == "datetime")
            {
                if (Regex.IsMatch(convertValue, @"[〇零一二三四五六七八九十\s]+"))
                {
                    string year = Regex.Match(convertValue, "[^年]+(?=年)").Value;
                    string month = Regex.Match(convertValue, "[^年月]+(?=月)").Value;
                    string day = Regex.Match(convertValue, "[^年月日]+(?=日)").Value;

                    year = LdFormat.FormatChDateTimeNumber(year).ToString();
                    month = LdFormat.FormatChDateTimeNumber(month).ToString();
                    day = LdFormat.FormatChDateTimeNumber(day).ToString();
                    day = (day == "0") ? "01" : day;

                    convertValue = year + "-" + month + "-" + day;
                }
                DateTime oNewTime;
                if (!DateTime.TryParse(convertValue, out oNewTime))
                    convertValue = string.Empty;
            }

            return convertValue;
        }

        /// <summary>
        /// 二审转时间用
        /// 按数据库字段类型，对字段值进行格式化。
        /// </summary>
        /// <param name="fieldType">字段类型</param>
        /// <param name="currFieldValue">字段值</param>
        /// <returns>格式化后的值。</returns>
        public static string NewSecondFormatDataField(string fieldType, string currFieldValue)
        {
            string convertValue = currFieldValue;
            if (fieldType == "" || fieldType == "varchar" || fieldType == "nvarchar" || fieldType == "ntext")
            {
                fieldType = "string";
            }
            if ((fieldType == "int" || fieldType == "money") && !Regex.IsMatch(convertValue, @"^\d*$"))
            {
                //支持对不规范的日期区间，转化为天数！
                if (Regex.IsMatch(currFieldValue, "年|月"))
                {
                    double nYear = LdFormat.DecodeNumberCn(Regex.Match(currFieldValue, @"[零一二三四五六七八九十\d]*(?=年)").Value);
                    double nMonth = LdFormat.DecodeNumberCn(Regex.Match(currFieldValue, @"[零一二三四五六七八九十\d]*(?=个?月)").Value);
                    double nDay = LdFormat.DecodeNumberCn(Regex.Match(currFieldValue, @"[零一二三四五六七八九十\d]*(?=日|天)").Value);

                    convertValue = (nYear * 360 + nMonth * 30 + nDay).ToString();
                }
                else
                    convertValue = LdFormat.DecodeNumberCn(convertValue).ToString();
            }

            if (fieldType == "datetime")
            {
                if (Regex.IsMatch(convertValue, @"[〇零一二三四五六七八九十\s]+"))
                {
                    string year = Regex.Match(convertValue, "[^年]+(?=年)").Value;
                    string month = Regex.Match(convertValue, "[^年月]+(?=月)").Value;
                    string day = Regex.Match(convertValue, "[^年月日]+(?=日)").Value;

                    year = LdFormat.FormatChDateTimeNumber(year).ToString();
                    month = LdFormat.FormatChDateTimeNumber(month).ToString();
                    day = LdFormat.FormatChDateTimeNumber(day).ToString();
                    day = (day == "0") ? "01" : day;

                    convertValue = year + "-" + month + "-" + day;
                }
                DateTime oNewTime;
                if (!DateTime.TryParse(convertValue, out oNewTime))
                    convertValue = null;
                else
                    convertValue = oNewTime.ToString("yyyy-MM-dd HH:mm:ss");
            }

            return convertValue;
        }
        /// <summary>
        /// 格式化中文日期
        /// </summary>
        /// <param name="currValue">字段值</param>
        /// <returns>格式化的值</returns>
        public static string FormatChDateTimeNumber(string currValue)
        {
            double resultValue = 0;

            currValue = currValue.Replace("〇", "零");
            if (Regex.IsMatch(currValue, "^十"))
            {
                currValue = Regex.Replace(currValue, "^十", "一十");

                if (currValue.Substring(currValue.Length - 1) != "十")
                {
                    currValue = Regex.Replace(currValue, "十", "");
                }
            }
            else
            {
                currValue = Regex.Replace(currValue, "十", "");
            }



            for (int i = 0; i < currValue.Length; i++)
            {
                char vChar = currValue[i];

                int j = 0;
                if (Regex.IsMatch(vChar.ToString(), @"\d"))
                {
                    j = int.Parse(vChar.ToString());
                }

                else
                {
                    j = "零一二三四五六七八九十".IndexOf(vChar);
                }
                if (j >= 0)
                {
                    resultValue += j * Math.Pow(10, currValue.Length - i - 1);
                }
            }

            return resultValue.ToString();
        }

        /// <summary>
        /// 格式化日期计算
        /// </summary>
        /// <param name="relatDateStr">2015-11-13</param>
        /// <param name="computeWord">次日|第二天</param>
        /// <returns>返回计算结果值</returns>
        [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1631:DocumentationMustMeetCharacterPercentage", Justification = "Reviewed.")]
        public static string FormatDateCompute(string relatDateStr, string computeWord)
        {
            string standardDate = FormatDataField("datetime", relatDateStr);

            DateTime oRelatTime = DateTime.Parse(standardDate);

            switch (computeWord)
            {
                case "当日":
                case "同日":
                    return standardDate;
                case "次日":
                case "第二天":
                case "第2天":
                    return oRelatTime.AddDays(1).ToShortDateString();
            }

            return "";
        }
        /// <summary>
        /// 转换阿拉伯数字转大写
        /// </summary>
        /// <param name="num">阿拉伯数字</param>
        /// <returns>返回大写形式</returns>
        public static string CmycurD(int num)
        {

            string str1 = "零一二三四五六七八九";            //0-9所对应的汉字
            string str2 = "个十百千万亿"; //数字位所对应的汉字 
            string str3 = "";    //从原num值中取出的值
            string str4 = num.ToString();    //数字的字符串形式
            string str5 = "";  //返回大写内容  
            string ch1 = "";    //数字的汉语读法
            string ch2 = "";    //数字位的汉字读法
            int nzero = 0;  //用来计算连续的零值是几个
            int temp;            //从原num值中取出的值

            int j = str4.Length;      //找出最高位 

            //循环取出每一位需要转换的值
            for (int i = 0; i < j; i++)
            {
                str3 = str4.Substring(i, 1);          //取出需转换的某一位的值
                temp = Convert.ToInt32(str3);      //转换为数字
                if (i != (j - 7) && i != (j - 11) && i != (j - 15))
                {
                    if (str3 == "0")
                    {
                        ch1 = "";
                        ch2 = "";
                        nzero = nzero + 1;
                    }
                    else
                    {
                        if (str3 != "0" && nzero != 0)
                        {
                            ch1 = "零" + str1.Substring(temp * 1, 1);
                            ch2 = str2.Substring(j - 1 - i, 1);
                            nzero = 0;
                        }
                        else
                        {
                            ch1 = str1.Substring(temp, 1);//截取数字位
                            ch2 = str2.Substring(j - 1 - i, 1);
                            nzero = 0;
                        }
                    }
                }
                if (ch2 == "个")
                {
                    ch2 = string.Empty;
                }
                str5 = str5 + ch1 + ch2;
            }

            return str5;
        }
        /// <summary>
        /// 反转文本
        /// </summary>
        /// <param name="srcText">原字符串</param>
        /// <returns>反转后的文本</returns>
        public static string Reverse(string srcText)
        {
            char[] TextArr = srcText.ToCharArray();
            Array.Reverse(TextArr);
            return new string(TextArr);
        }


        //private static Regex specCharReplaceReg = new Regex(@"[\^\$(){}?*+.\\\[\]\|]");        //替换正则元字符的正则
        /// <summary>
        /// 转换为正则表达式文本(替换源字符中的正则元字符)
        /// </summary>
        /// <param name="srcText">源文本字符串</param>
        /// <returns>返回转换后的正则表达式</returns>
        public static string ReverseToRegexText(string srcText)
        {
            return Regex.Replace(srcText, @"[\^\$(){}?*+.\\\[\]\|]", @"\$0");
            //return LdFormat.specCharReplaceReg.Replace(srcText, @"\$0");                     //替换正则元字符。
        }

        #region 添加表数据
        /// <summary>
        /// 获取表数据的集合
        /// </summary>
        /// <param name="keyValuePairs">键值集合</param>
        /// <param name="Key">键</param>
        /// <returns></returns>
        public static List<Dictionary<string, string>> GetTableDicValue(Dictionary<string, List<Dictionary<string, string>>> keyValuePairs, string Key)
        {
            if (keyValuePairs != null && keyValuePairs.ContainsKey(Key.ToLower()))
            {
                return keyValuePairs[Key.ToLower()];
            }
            else
            {
                List<Dictionary<string, string>> rows = new List<Dictionary<string, string>>();
                return rows;
            }
        }
        /// <summary>
        /// 添加表数据
        /// </summary>
        /// <param name="keyValuePairs">数据集合</param>
        /// <param name="Key">被添加的表</param>
        /// <param name="row">需要添加的行数据</param>
        public static void AddTableDicValue(Dictionary<string, List<Dictionary<string, string>>> keyValuePairs, string Key, Dictionary<string, string> row)
        {
            if (!keyValuePairs.ContainsKey(Key.ToLower()))
            {
                List<Dictionary<string, string>> rows = new List<Dictionary<string, string>>();
                keyValuePairs.Add(Key.ToLower(), rows);
            }
            keyValuePairs[Key.ToLower()].Add(row);
        }


        #endregion

        #region 行数据的修改与添加
        /// <summary>
        /// 根据键值内容集合，根据键返回值
        /// </summary>
        /// <param name="keyValuePairs">键值集合</param>
        /// <param name="Key">键</param>
        /// <returns></returns>
        public static string GetDicValue(IDictionary<string, string> keyValuePairs, string Key)
        {
            if (keyValuePairs != null && keyValuePairs.ContainsKey(Key.ToLower()))
            {
                return keyValuePairs[Key.ToLower()];
            }
            else
            {
                return "";
            }
        }
        /// <summary>
        /// 将当前的内容添加到指定的集合中
        /// </summary>
        /// <param name="keyValuePairs">键值集合</param>
        /// <param name="Key">键</param>
        /// <param name="value">键</param>
        /// <returns></returns>
        public static void AddDicValue(Dictionary<string, string> keyValuePairs, string Key, string value)
        {
            if (keyValuePairs.ContainsKey(Key.ToLower()))
            {
                keyValuePairs[Key.ToLower()] = value;
            }
            else
            {
                keyValuePairs.Add(Key.ToLower(), value);
            }
        }


        #endregion


        /// <summary>
        /// 将datarow转换为dic 数据
        /// </summary>
        /// <param name="row">DataRow</param>
        /// <returns></returns>
        public static Dictionary<string, string> DataRowToDic(DataRow row)
        {
            Dictionary<string, string> result = new Dictionary<string, string>();
            foreach (DataColumn column in row.Table.Columns)
            {
                result.Add(column.ColumnName.ToLower(), Convert.ToString(row[column]));
            }
            return result;
        }

        #region 将键值数据转实体对象
        /// <summary>
        /// 将Dic集合数据转为对象数据
        /// </summary>
        /// <typeparam name="T">需要转换的对象</typeparam>
        /// <param name="keyValues">Dic数据</param>
        /// <returns></returns>
        public static T DicToObject<T>(Dictionary<string, string> keyValues) where T : class
        {
            T model = Activator.CreateInstance<T>();
            System.Reflection.PropertyInfo[] properties = model.GetType().GetProperties();
            if (properties.Length > 0 && keyValues.Count() > 0)
            {
                foreach (var property in properties)
                {
                    if (keyValues.ContainsKey(property.Name.ToLower()))
                    {
                        property.SetValue(model, keyValues[property.Name.ToLower()], null);
                    }
                }
            }
            return model;
        }


        #endregion

        #region 将键值对数据转dataTable
        /// <summary>
        /// 根据传入的键值集合返回一个数据表集合
        /// </summary>
        /// <param name="dictable">键表数据</param>
        /// <returns></returns>
        public static List<DataTable> GetDictConvertDataTable(Dictionary<string, List<Dictionary<string, string>>> dictable)
        {
            List<DataTable> dataTables = new List<DataTable>();

            foreach (var Temptable in dictable)
            {
                DataTable table = new DataTable();
                table.TableName = Temptable.Key;//获取到表名称

                foreach (var rows in Temptable.Value)
                {//获取到表数据集合
                    foreach (var colName in rows.Keys)
                    {//遍历所有的key为表的列；
                        if (!table.Columns.Contains(colName))
                        {
                            table.Columns.Add(colName, typeof(string));
                        }

                    }
                    DataRow dtrow = table.NewRow();//创建一行数据
                    foreach (KeyValuePair<string, string> item in rows)
                    {//将所有的对应数据添加其中
                        dtrow[item.Key] = item.Value;
                    }
                    table.Rows.Add(dtrow);
                }

                dataTables.Add(table);
            }

            return dataTables;
        }

        /// <summary>
        /// 传入键值，返回一个数据表
        /// </summary>
        /// <param name="dicList">键值数据</param>
        /// <returns></returns>
        public static DataTable GetDictConvertDataTable(List<Dictionary<string, string>> dicList)
        {
            DataTable table = new DataTable();
            foreach (var dic in dicList)
            {
                foreach (var colName in dic.Keys)
                {//遍历所有的key为表的列；
                    if (!table.Columns.Contains(colName))
                        table.Columns.Add(colName, typeof(string));
                }

                DataRow dtrow = table.NewRow();//创建一行数据
                foreach (KeyValuePair<string, string> item in dic)
                {//将所有的对应数据添加其中
                    dtrow[item.Key] = item.Value;
                }
                table.Rows.Add(dtrow);
            }

            return table;
        }


        #endregion

        #region 汉字转数字
        public static string CharToNumber(string c)
        {
            switch (c)
            {
                case "一": return "1";
                case "二": return "2";
                case "三": return "3";
                case "四": return "4";
                case "五": return "5";
                case "六": return "6";
                case "七": return "7";
                case "八": return "8";
                case "九": return "9";
                case "零": return "0";
                case "两": return "2";
                case "俩": return "2";
                default: return c;
            }
        }

        public static string NumberToChar(string c)
        {
            switch (c)
            {
                case "1": return "一";
                case "2": return "二";
                case "3": return "三";
                case "4": return "四";
                case "5": return "五";
                case "6": return "六";
                case "7": return "七";
                case "8": return "八";
                case "9": return "九";
                case "零": return "0";
                case "两": return "2";
                case "俩": return "2";
                default: return c;
            }
        }
        #endregion

        #region Xml 逻辑处理
        /// <summary>
        /// 替换xml中的非法字符
        /// </summary>
        /// <param name="sourceXml">xml原文</param>
        /// <returns></returns>
        public static string EscapeXml(string sourceXml)
        {
            string result = "";

            result = sourceXml.Replace("&", "&amp;");

            return result;
        }


        #endregion

        

        #region 文件处理
        /// <summary>
        /// 加载配置文件
        /// </summary>
        /// <param name="casuseID"></param>
        /// <returns></returns>
        public static XmlDocument GetOpXml(string casuseID)
        {

            XmlDocument getop = new XmlDocument();
            if (!string.IsNullOrEmpty(casuseID))
            {
                getop.Load(BllDataHandle.GetCurrentProgramPath() + "Config//Deduction//" + casuseID + ".xml");
            }
            return getop;
        }
        #endregion
    }
}
